﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DataProvider
/// </summary>
public class DataProvider
{
    
    public static SqlConnection sqlConnection;
    public static DataTable objDataTable;
    public static String str = null;
  
    public static SqlConnection CreateConnection()
    {


        SqlConnection sqlConnection;
        sqlConnection = new SqlConnection();
        try
        {
            sqlConnection.ConnectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=FashionShop;Integrated Security=True";
            sqlConnection.Open();
        }
        catch (Exception ex)
        {
            
        }
        return sqlConnection;
    }
    
    #region "Lấy 1 datatable từ 1 câu truy vấn"
    public static DataTable GetDataTable(string strSQL)
    {
        sqlConnection = new SqlConnection();
        try
        {
            sqlConnection = CreateConnection();
            SqlDataAdapter sqlAdapter = new SqlDataAdapter();
            SqlCommand objcommand = new SqlCommand();
            objcommand.Connection = sqlConnection;
            objcommand.CommandType = CommandType.Text;
            objcommand.CommandText = strSQL;
            SqlDataAdapter objsqlAdapter = new SqlDataAdapter();
            objsqlAdapter.SelectCommand = objcommand;
            objDataTable = new DataTable("");
            objsqlAdapter.Fill(objDataTable);
            sqlConnection.Close();
            sqlConnection.Dispose();
            sqlConnection = null;
        }
        catch (System.Exception ex)
        {

        }
        return objDataTable;

    }
    #endregion
    //======================================= End ===========================================================//

    
}
